package com.whj.servicedriveruser.service.impl;

import com.whj.internalcommon.dto.DriverUserWorkStatus;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import com.whj.servicedriveruser.service.DriverUserWorkStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whj
 * @since 2023-01-15
 */
@Service
public class DriverUserWorkStatusServiceImpl implements DriverUserWorkStatusService {

    @Autowired
    private DriverUserWorkStatusMapper driverUserWorkStatusMapper;

    /**
     * 根据driverId 修改司机状态
     * @param driverId
     * @param workStatus
     * @return
     */
    @Override
    public ResponseResult changeWorkStatus(Long driverId, Integer workStatus) {

        LocalDateTime now = LocalDateTime.now();
        Map<String,Object> map =new HashMap<>();
        map.put("driver_id",driverId);
        List<DriverUserWorkStatus> driverUserWorkStatuses = driverUserWorkStatusMapper.selectByMap(map);

        DriverUserWorkStatus driverUserWorkStatus = driverUserWorkStatuses.get(0);
        driverUserWorkStatus.setWorkStatus(workStatus);
        driverUserWorkStatus.setCreateTime(now);
        driverUserWorkStatus.setUpdateTime(now);

        driverUserWorkStatusMapper.updateById(driverUserWorkStatus);

        return ResponseResult.success("");
    }

    @Override
    public ResponseResult<DriverUserWorkStatus> getWorkStatus(Long driverId) {
        Map<String,Object> queryMap = new HashMap<>();
        queryMap.put("driver_id",driverId);
        List<DriverUserWorkStatus> driverUserWorkStatuses = driverUserWorkStatusMapper.selectByMap(queryMap);
        DriverUserWorkStatus driverUserWorkStatus = driverUserWorkStatuses.get(0);

        return ResponseResult.success(driverUserWorkStatus);
    }
}
